'use strict';

import { basicAction } from '@peace/utils';
import { ApiTable } from '$utils';

// 获取专利列表（分页）
export function getPatentList(params) {
  return dispatch => basicAction({
    type: 'get',
    dispatch: dispatch,
    actionType: 'GET_PATENT_LIST',
    url: `${ApiTable.getPatentList}`,
    query: params,
    msg: { error: '获取专利列表失败' },
    reducer: { name: 'patentList' }
  });
}

// 编辑/新增专利
export function editPatent(id, data) {
  return dispatch => basicAction({
    type: 'post',
    dispatch: dispatch,
    actionType: 'EDIT_PATENT',
    url: `${ApiTable.editPatent.replace(':id', id)}`,
    data: data,
    msg: { error: '保存专利信息失败' },
    reducer: { name: 'editPatentResult' }
  });
}

// 删除专利
export function deletePatent(id) {
  return dispatch => basicAction({
    type: 'del',
    dispatch: dispatch,
    actionType: 'DELETE_PATENT',
    url: `${ApiTable.deletePatent.replace(':id', id)}`,
    msg: { error: '删除专利失败' },
    reducer: { name: 'deletePatentResult' }
  });
}

// 导入专利数据
export function importPatents(formData) {
  return dispatch => basicAction({
    type: 'post',
    dispatch: dispatch,
    actionType: 'IMPORT_PATENTS',
    url: `${ApiTable.importPatents}`,
    data: formData,
    msg: { error: '导入专利数据失败' },
    reducer: { name: 'importPatentsResult' }
  });
}

// 变更专利权人
export function changePatentee(id, data) {
  return dispatch => basicAction({
    type: 'post',
    dispatch: dispatch,
    actionType: 'CHANGE_PATENTEE',
    url: `${ApiTable.changePatentee.replace(':id', id)}`,
    data: data,
    msg: { error: '变更专利权人失败' },
    reducer: { name: 'changePatenteeResult' }
  });
}

// 导出专利数据
export function exportPatents(params) {
  return dispatch => basicAction({
    type: 'get',
    dispatch: dispatch,
    actionType: 'EXPORT_PATENTS',
    url: `${ApiTable.exportPatents}`,
    query: params,
    msg: { error: '导出专利数据失败' },
    reducer: { name: 'exportPatentsResult' }
  });
}

// 获取专利导入模板
export function getPatentTemplate() {
  return dispatch => basicAction({
    type: 'get',
    dispatch: dispatch,
    actionType: 'GET_PATENT_TEMPLATE',
    url: `${ApiTable.getPatentTemplate}`,
    msg: { error: '获取专利导入模板失败' },
    reducer: { name: 'patentTemplateResult' }
  });
} 